﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Collector.Device
{
    public class PulseGeneralCollector : IPulseCollectorFactory
    {
        private readonly string TAG = "PulseGeneralCollector:";
        private readonly byte LENGTH_OFFSET = 0x04;
        private readonly byte CMD_OFFSET = 0x05;
        private IDeviceCommunication mDeviceAdapter;

        public IDeviceCommunication DeviceAdapter
        {
            get { return mDeviceAdapter; }
            set { mDeviceAdapter = value; }
        }

        public virtual void AirFrameProcessing(byte[] frame)
        {
            //no-nothing
        }

        public virtual void ControlFrameProcessing(byte[] frame)
        {
            DeviceEvent evt = (DeviceEvent)frame[CMD_OFFSET];
            Log.Debug(TAG + "ControlFrameProcessing() {0} evt code: {1}", ConvertFuncs.ByteArrayToHexString(frame), evt);
            switch (evt)
            {
                case DeviceEvent.eDEV_EVENT_REACHED:
                    {
                        // 回复设备收到A7事件
                        if (mDeviceAdapter != null)
                        {
                            mDeviceAdapter.GivebackCompleted(evt);
                        }
                    }
                    break;
                case DeviceEvent.eDEV_EVENT_OVERFLOW:
                    {

                    }
                    break;
                case DeviceEvent.eDEV_EVENT_RESET:
                    {
                        // 回复设备收到A4事件
                        if (mDeviceAdapter != null)
                        {
                            mDeviceAdapter.GivebackCompleted(evt);
                        }
                    }
                    break;
                default:
                    {
                        
                    }
                    break;

            }
        }

        public virtual void PulseFrameProcessing(byte[] frame)
        {
            //no-nothing
        }
    }
}
